//
//  ZhengZhuangViewController.m
//  安好
//
//  Created by rlp on 14-12-10.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "ZhengZhuangViewController.h"
#import "OBShapedButton.h"

@interface ZhengZhuangViewController ()

@end

@implementation ZhengZhuangViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.edgesForExtendedLayout=UIRectEdgeNone;

    [self makeNavBarView];

    NSArray *keyArray = [[NSArray alloc] initWithObjects:@"1", @"8", @"12", @"17", @"24", @"34", @"38", @"49", @"53", @"56", @"58", @"69", @"79", @"80", nil];
    NSArray *valueArray = [[NSArray alloc] initWithObjects:@"头部", @"上肢", @"下肢", @"胸部", @"腹部", @"颈部", @"骨", @"腰部", @"盆腔", @"臀部", @"生殖部位", @"全身", @"生殖部位", @"其他", nil];
    self.partNameDict = [[NSMutableDictionary alloc] initWithObjects:valueArray forKeys:keyArray];
    
    
    ZJSwitch *switch2 = [[ZJSwitch alloc] initWithFrame:CGRectMake(20, 100, 70, 31)];
    switch2.backgroundColor = [UIColor clearColor];
    switch2.tintColor = [ClassMethodsViewController colorWithHexString:@"#4fc1e9"];
    switch2.onTintColor = [ClassMethodsViewController colorWithHexString:@"#4fc1e9"];
    switch2.onText = @"女";
    switch2.offText = @"男";
    switch2.on = NO;
    switch2.tag = 993;
    [switch2 addTarget:self action:@selector(handleSwitchEvent:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:switch2];
    
    ZJSwitch *switch3 = [[ZJSwitch alloc] initWithFrame:CGRectMake(20, 60, 70, 31)];
    switch3.backgroundColor = [UIColor clearColor];
    switch3.tintColor = [ClassMethodsViewController colorWithHexString:@"#4fc1e9"];
    switch3.onTintColor = [ClassMethodsViewController colorWithHexString:@"#4fc1e9"];
    switch3.onText = @"反";
    switch3.offText = @"正";
    switch3.on = NO;
    switch3.tag = 992;
    [switch3 addTarget:self action:@selector(handleSwitchEvent:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:switch3];
    
    
    self.pointImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"renti_point"]];
    self.pointImageView.frame = CGRectMake(100, 100, 16, 16);
    
    
    //左侧的数组和tableview
    self.leftDataArray = [[NSMutableArray alloc] init];
    self.leftTableView = [[UITableView alloc] initWithFrame: CGRectMake(0, 0, kScreenWidth/3,  kScreenHeight-iOS7TopMargin) style:UITableViewStylePlain];
    self.leftTableView.delegate = self;
    self.leftTableView.dataSource = self;
//    if(IOS7_OR_LATER)
//        self.leftTableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.leftTableView.tag = 100;
    self.leftTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
//    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 15)];
//    view.backgroundColor = [ClassMethodsViewController colorWithHexString:@"#ecf4f6"];
//    self.leftTableView.tableHeaderView = view;
    
    //右侧的数组和tableview
    self.rightDataArray = [[NSMutableArray alloc] init];
    self.rightTableView = [[UITableView alloc] initWithFrame: CGRectMake(self.leftTableView.frame.origin.x, self.leftTableView.frame.origin.y, kScreenWidth/3*2, self.leftTableView.frame.size.height) style:UITableViewStylePlain];
    self.rightTableView.delegate = self;
    self.rightTableView.dataSource = self;
//    if(IOS7_OR_LATER)
//        self.rightTableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.rightTableView.tag = 101;
    self.rightTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.rightTableView.backgroundColor = [ClassMethodsViewController colorWithHexString:BACK_BACKGROUNDCOLOR_16];
    self.rightTableView.layer.backgroundColor =[ClassMethodsViewController colorWithHexString:LINE_BACKGROUNDCOLOR_16].CGColor;
    
//    UIView * view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 15)];
//    view1.backgroundColor = [ClassMethodsViewController colorWithHexString:@"#ecf4f6"];
//    self.rightTableView.tableHeaderView = view1;
    
    
    //手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manImageView.userInteractionEnabled = YES;
    [self.manImageView addGestureRecognizer:tap];
    
    //男人 前面 所有的部位都填加了手势，根据相应的图片进行相应的网络请求
    UITapGestureRecognizer *tapTou = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manFrontTou.userInteractionEnabled = YES;
    [self.manFrontTou addGestureRecognizer:tapTou];
    UITapGestureRecognizer *tapXiong = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manFrontXiong.userInteractionEnabled = YES;
    [self.manFrontXiong addGestureRecognizer:tapXiong];
    UITapGestureRecognizer *tapFu = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manFrontFu.userInteractionEnabled = YES;
    [self.manFrontFu addGestureRecognizer:tapFu];
    UITapGestureRecognizer *tapShengzhi = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manFrontShengzhi.userInteractionEnabled = YES;
    [self.manFrontShengzhi addGestureRecognizer:tapShengzhi];
    UITapGestureRecognizer *tapXiazhi = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manFrontXiazhi.userInteractionEnabled = YES;
    [self.manFrontXiazhi addGestureRecognizer:tapXiazhi];
    UITapGestureRecognizer *tapGebo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manFrontGebo.userInteractionEnabled = YES;
    [self.manFrontGebo addGestureRecognizer:tapGebo];
    UITapGestureRecognizer *tapGeboLeft = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manFrontGeboLeft.userInteractionEnabled = YES;
    [self.manFrontGeboLeft addGestureRecognizer:tapGeboLeft];
    
    //男人 后面
    UITapGestureRecognizer *tapJing = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manBackJing.userInteractionEnabled = YES;
    [self.manBackJing addGestureRecognizer:tapJing];
    UITapGestureRecognizer *tapJizhu = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manBackJizhu.userInteractionEnabled = YES;
    [self.manBackJizhu addGestureRecognizer:tapJizhu];
    UITapGestureRecognizer *tapYao = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manBackPengqiang.userInteractionEnabled = YES;
    [self.manBackPengqiang addGestureRecognizer:tapYao];
    UITapGestureRecognizer *tapPengqiang = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manBackTun.userInteractionEnabled = YES;
    [self.manBackTun addGestureRecognizer:tapPengqiang];
    UITapGestureRecognizer *tapTun = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.manBackYao.userInteractionEnabled = YES;
    [self.manBackYao addGestureRecognizer:tapTun];
    
    //女人 前面
    UITapGestureRecognizer *tapTouNv = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_front_tou.userInteractionEnabled = YES;
    [self.wemon_front_tou addGestureRecognizer:tapTouNv];
    UITapGestureRecognizer *tapXiongNv = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_front_Xiong.userInteractionEnabled = YES;
    [self.wemon_front_Xiong addGestureRecognizer:tapXiongNv];
    UITapGestureRecognizer *tapFuNv = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_front_Fu.userInteractionEnabled = YES;
    [self.wemon_front_Fu addGestureRecognizer:tapFuNv];
    UITapGestureRecognizer *tapShengzhiNv = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_front_Shengzhi.userInteractionEnabled = YES;
    [self.wemon_front_Shengzhi addGestureRecognizer:tapShengzhiNv];
    UITapGestureRecognizer *tapTuiNv = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_front_Tui.userInteractionEnabled = YES;
    [self.wemon_front_Tui addGestureRecognizer:tapTuiNv];
    UITapGestureRecognizer *tapWemonGeboLeft = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_gebo_left.userInteractionEnabled = YES;
    [self.wemon_gebo_left addGestureRecognizer:tapWemonGeboLeft];
    UITapGestureRecognizer *tapWemonGeboRight = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_gebo_right.userInteractionEnabled = YES;
    [self.wemon_gebo_right addGestureRecognizer:tapWemonGeboRight];
    
    //女人 后面
    UITapGestureRecognizer *tapJingNv = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_front_Jing.userInteractionEnabled = YES;
    [self.wemon_front_Jing addGestureRecognizer:tapJingNv];
    UITapGestureRecognizer *tapJizhuNv = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_back_jizhu.userInteractionEnabled = YES;
    [self.wemon_back_jizhu addGestureRecognizer:tapJizhuNv];
    UITapGestureRecognizer *tapYaoNv = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_back_yao.userInteractionEnabled = YES;
    [self.wemon_back_yao addGestureRecognizer:tapYaoNv];
    UITapGestureRecognizer *tapPengqiangNv = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_back_penqiang.userInteractionEnabled = YES;
    [self.wemon_back_penqiang addGestureRecognizer:tapPengqiangNv];
    UITapGestureRecognizer *tapTunNv = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked:)];
    self.wemon_back_tun.userInteractionEnabled = YES;
    [self.wemon_back_tun addGestureRecognizer:tapTunNv];
}
#pragma mark - 触发点击手势
-(void)tapClicked:(UIGestureRecognizer *)ges
{
    CGPoint pointImageView = [ges locationInView:self.view];
    CGPoint point = [ges locationOfTouch:0 inView:ges.view];
    UIImageView *imageView = (UIImageView *)ges.view;
    
    //判断点击的坐标的颜色是否是可见的
    if(![self isAlphaVisibleAtPoint:point forImage:imageView.image andView:ges.view])
    {
        self.pointImageView.frame = CGRectMake(pointImageView.x - 8, pointImageView.y - 8, 16, 16);
        [self.view addSubview:self.pointImageView];
        
        
        UISwitch * switch1 = (UISwitch *)[self.view viewWithTag:992];
        UISwitch * switch2 = (UISwitch *)[self.view viewWithTag:993];
        
        //1 为男人，1 为正面
        self.man = switch2.on ? @"1" : @"2";
        self.face = switch1.on ? @"2" : @"1";
        //根据部位id 男女 正反面获取部位的症状
        [self getSomePart:[NSString stringWithFormat:@"%ld", imageView.tag - 200] man:self.man face:self.face];
        
        self.title = [self.partNameDict objectForKey:[NSString stringWithFormat:@"%ld", imageView.tag - 200]];
        
        //动画推出左侧的tableview
        [self showTableViewAnimation];
    }
}
//动画推出左侧的tableview
-(void)showTableViewAnimation
{
    page = 1;
    
    [self.view addSubview:self.rightTableView];
    [self.view addSubview:self.leftTableView];
    
    [self.leftDataArray removeAllObjects];
    [self.rightDataArray removeAllObjects];
    [self.rightTableView reloadData];
    
    //先在左侧的tableview中添加一个返回
    [self.leftDataArray addObject:@"返回"];
    [self.leftTableView reloadData];
    
    [UIView animateWithDuration:0.35f animations:^{
        self.leftTableView.frame = CGRectMake(0, 0,kScreenWidth/3,  kScreenHeight-iOS7TopMargin);
    } completion:^(BOOL finished){
        
    }];
    [UIView animateWithDuration:0.55f animations:^{
        self.rightTableView.frame =  CGRectMake(self.leftTableView.frame.size.width, self.leftTableView.frame.origin.y, kScreenWidth/3*2, self.leftTableView.frame.size.height);
    } completion:^(BOOL finished){
        [self.pointImageView removeFromSuperview];
    }];
}
//动画隐藏左侧的tableview
-(void)hideTableViewAnimation
{
    [UIView animateWithDuration:0.4f animations:^{
        self.leftTableView.frame = CGRectMake(-kScreenWidth, 0,kScreenWidth/3,  kScreenHeight-iOS7TopMargin);

        self.rightTableView.frame =  CGRectMake(self.leftTableView.frame.size.width-kScreenWidth, self.leftTableView.frame.origin.y, kScreenWidth/3*2, self.leftTableView.frame.size.height);
    } completion:^(BOOL finished){
        [self.leftTableView removeFromSuperview];
        [self.rightTableView removeFromSuperview];
    }];
}
-(void)viewWillAppear:(BOOL)animated
{
    [self.rightTableView deselectRowAtIndexPath:[self.rightTableView indexPathForSelectedRow] animated:YES];
}
#pragma mark - tableview delegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(tableView.tag == 100)
        return [self.leftDataArray count];
    return [self.rightDataArray count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return ((kScreenWidth == 414) ? 44*1.2 : 44);
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *ID=@"tableViewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    
    
    if (tableView == self.leftTableView) {

    cell.textLabel.font = [UIFont systemFontOfSize:LABEL_FONT_SIZE_CONTENT];
        
        @try {
            if(indexPath.row == 0)
                cell.textLabel.text = [self.leftDataArray objectAtIndex:indexPath.row];
            else
                cell.textLabel.text = [[self.leftDataArray objectAtIndex:indexPath.row] objectForKey:@"partname"];
        }
        @catch (NSException *exception) {
            MyNSLog("exception = %@", exception);
        }
    
    /**
     *  线条的处理
     */
    
    UIView *bottomLineView = [[UIView alloc]initWithFrame:CGRectMake(5, ((kScreenWidth == 414) ? 44*1.2 : 44)-1,kScreenWidth-5, 0.5)];

    bottomLineView.backgroundColor = [ClassMethodsViewController colorWithHexString:LINE_BACKGROUNDCOLOR_16];
    [cell addSubview:bottomLineView];

    cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
    cell.selectedBackgroundView.backgroundColor = [ClassMethodsViewController colorWithHexString:LINE_BACKGROUNDCOLOR_16];
}else if (tableView == self.rightTableView){
    cell.textLabel.font = [UIFont systemFontOfSize:LABEL_FONT_SIZE_CONTENT];
    
    @try {
        cell.textLabel.text = [[self.rightDataArray objectAtIndex:indexPath.row] objectForKey:@"symptomname"];
    }
    @catch (NSException *exception) {
        MyNSLog("exception = %@", exception);
    }

    
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    /**
     *  线条的处理
     */
    
    UIView *bottomLineView = [[UIView alloc]initWithFrame:CGRectMake(5,((kScreenWidth == 414) ? 44*1.2 : 44)-1,kScreenWidth-5, 0.5)];
    
    bottomLineView.backgroundColor = [ClassMethodsViewController colorWithHexString:LINE_BACKGROUNDCOLOR_16];
    [cell addSubview:bottomLineView];
    cell.backgroundColor = [ClassMethodsViewController colorWithHexString:LINE_BACKGROUNDCOLOR_16];
    
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
}



    
    
    
    
    
          return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //tag == 100 是左侧的tablev ，否则是右侧的tableview
    if(tableView == self.leftTableView)
    {
        if(indexPath.row == 0)
        {
            [self hideTableViewAnimation];
        }
        else
        {
            [self.leftTableView reloadData];
            [self.leftTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
            page = 1;
            [self loadDetailWithPart:indexPath.row];
            
            [self.rightDataArray removeAllObjects];
        }
    }
    else
    {

        SymptomDiseaseViewController *symptomDiseaseViewController = [[SymptomDiseaseViewController alloc]initWithNibName:@"SymptomDiseaseViewController" bundle:nil];
        symptomDiseaseViewController.symptomid =[[self.rightDataArray objectAtIndex:indexPath.row] objectForKey:@"symptomid"];
        symptomDiseaseViewController.title = [[self.rightDataArray objectAtIndex:indexPath.row] objectForKey:@"symptomname"];
        [self.navigationController pushViewController:symptomDiseaseViewController animated:YES];
    }
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSIndexPath *tmpIndexPath = [self.leftTableView indexPathForSelectedRow];
    if(tableView.tag != 100)
    {
        if(indexPath.row == [self.rightDataArray count] - 1)
        {
            if (self.rightDataArray.count>=20) {
                page ++;

            }
            
            [self loadDetailWithPart:tmpIndexPath.row];
        }
    }
}
#pragma mark - 获取某部位的的具体信息
-(void)getSomePart:(NSString *)partId man:(NSString *)man face:(NSString *)face
{
    
    
    
    
    [self showActionView];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:10];
    [dict setObject:kPlatform forKey:@"platform"];
    [dict setObject:kVersion forKey:@"version"];
    [dict setObject:man forKey:@"gender"];  //男或女
    [dict setObject:face forKey:@"face"];       //正面或反面
    [dict setObject:partId forKey:@"fpartid"];   //部位id
    

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:[NSString stringWithFormat:@"%@%@",kBaseURL,@"/symptom/partlist/"] parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
        MyNSLog("成功");
        NSNumber * statusNum = [responseObject objectForKey:@"status"];
        //用NSNumberFormatter把 NSNumber类型的数字-->转成字符串
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString * statusString = [numberFormatter stringFromNumber:statusNum];//得到字符串对象: "0" / "1"
        MyNSLog("%@",responseObject);
        if ([statusString isEqualToString:@"0"]) {

            [self showCustomHudSingleLine:[responseObject objectForKey:@"msg"]];
        }else{
            if ([responseObject isKindOfClass:[NSDictionary class]]) {
                
                for(NSDictionary *subDic in [responseObject objectForKey:@"data"])
                {
                    [self.leftDataArray addObject:subDic];
                }
                
                [self.leftTableView reloadData];
                [self tableView:self.leftTableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];

            }else{
                [self showCustomHudSingleLine:@"网络数据格式错误"];
            }
            
        }
        [self hiddenActionView];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self hiddenActionView];
        
    }];
    
    
    
    
}
//根据部位获取该部位的疾病列表
-(void)loadDetailWithPart:(NSInteger)index
{
    
    
    
    [self showActionView];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:10];
    [dict setObject:kPlatform forKey:@"platform"];
    [dict setObject:kVersion forKey:@"version"];
    
    [dict setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];   //部位id
    [dict setObject:@"20" forKey:@"pagesize"];   //父级部位id
    [dict setObject:[[self.leftDataArray objectAtIndex:index] objectForKey:@"partid"] forKey:@"partid"];   //部位id
    [dict setObject:[[self.leftDataArray objectAtIndex:index] objectForKey:@"fpartid"] forKey:@"fpartid"];   //父级部位id
    
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:[NSString stringWithFormat:@"%@%@",kBaseURL,@"/symptom/partSymptom/"] parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
        MyNSLog("成功");
        NSNumber * statusNum = [responseObject objectForKey:@"status"];
        //用NSNumberFormatter把 NSNumber类型的数字-->转成字符串
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString * statusString = [numberFormatter stringFromNumber:statusNum];//得到字符串对象: "0" / "1"
        MyNSLog("%@",responseObject);
        if ([statusString isEqualToString:@"0"]) {
            [self showCustomHudSingleLine:[responseObject objectForKey:@"msg"]];
        }else{
            if ([responseObject isKindOfClass:[NSDictionary class]]) {
                
                NSDictionary *dataDict =[responseObject objectForKey:@"data"];
                for(NSString *key in [dataDict allKeys])
                {
                    for(NSDictionary *dict in [dataDict objectForKey:key])
                    {
                        [self.rightDataArray addObject:dict];
                    }
                }

                
                [self.rightTableView reloadData];
            }else{
                [self showCustomHudSingleLine:@"网络数据格式错误"];
            }
            
        }
        [self hiddenActionView];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self hiddenActionView];
        
    }];

    
    
    

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - 设置导航条
-(void)makeNavBarView
{
    //贴图
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonClicked:)];
    backBtnImg.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = backBtnImg;
    
    UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 23, 23)];
    [rightButton setTitle:@"文字" forState:UIControlStateNormal];
    rightButton.titleLabel.font = [UIFont systemFontOfSize:BUTTON_TEXTLABEL_FOUNT_SIZE];
    [rightButton addTarget:self action:@selector(rightButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [rightButton sizeToFit];
    UIBarButtonItem* rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
    
    
}

-(void)leftButtonClicked:(UIButton *)sender
{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
-(void)rightButtonClicked:(UIButton *)sender{
    JiZhenViewController *jizhen = [[JiZhenViewController alloc] init];
    jizhen.title = @"症状自查";
    jizhen.appendingString = @"/symptom/wz";
    [self.navigationController pushViewController:jizhen animated:YES];
  
}
//判断当前点击的point是否可见
- (BOOL)isAlphaVisibleAtPoint:(CGPoint)point forImage:(UIImage *)image andView:(UIView *)view
{
    CGSize iSize = image.size;
    CGSize bSize = view.bounds.size;
    point.x *= (bSize.width != 0) ? (iSize.width / bSize.width) : 1;
    point.y *= (bSize.height != 0) ? (iSize.height / bSize.height) : 1;
    
    UIColor *pixelColor = [image colorAtPixel:point];
    CGFloat alpha = 0.0;
    
    if ([pixelColor respondsToSelector:@selector(getRed:green:blue:alpha:)])
    {
        [pixelColor getRed:NULL green:NULL blue:NULL alpha:&alpha];
    }
    else
    {
        CGColorRef cgPixelColor = [pixelColor CGColor];
        alpha = CGColorGetAlpha(cgPixelColor);
    }
    
    return alpha >= kAlphaVisibleThreshold;

}
- (void)handleSwitchEvent:(UISwitch *)Switch
{
    UISwitch * switch1 = (UISwitch *)[self.view viewWithTag:992];
    UISwitch * switch2 = (UISwitch *)[self.view viewWithTag:993];
    
    if (Switch.tag == 992 ) {
        
        if (switch1.on) {
            if (switch2.on) {
                
                MyNSLog("111");
                self.manImageView.image = [UIImage imageNamed:@"女反"];
                self.wemon_front_tou.hidden = NO;
                self.wemon_front_Jing.hidden = NO;
                self.wemon_front_Tui.hidden = NO;
                
                self.wemon_front_Xiong.hidden = YES;
                self.wemon_front_Fu.hidden = YES;
                self.wemon_front_Shengzhi.hidden = YES;
                
                self.wemon_back_jizhu.hidden = NO;
                self.wemon_back_yao.hidden = NO;
                self.wemon_back_penqiang.hidden = NO;
                self.wemon_back_tun.hidden = NO;
                
                
                self.wemon_gebo_left.hidden = NO;
                self.wemon_gebo_right.hidden = NO;
                
                self.manFrontGeboLeft.hidden = YES;
                self.manFrontGebo.hidden = YES;
                self.manBackJing.hidden = YES;
                self.manBackJizhu.hidden = YES;
                self.manBackYao.hidden = YES;
                self.manBackPengqiang.hidden = YES;
                self.manBackTun.hidden = YES;
                
                self.manFrontTou.hidden = YES;
                self.manFrontXiong.hidden = YES;
                self.manFrontFu.hidden = YES;
                self.manFrontShengzhi.hidden = YES;
                self.manFrontXiazhi.hidden =YES;
                
                
            }else{
                MyNSLog("222");
                self.manImageView.image = [UIImage imageNamed:@"男反面"];
                self.wemon_front_tou.hidden = YES;
                self.wemon_front_Jing.hidden = YES;
                self.wemon_front_Tui.hidden = YES;
                
                self.wemon_front_Xiong.hidden = NO;
                self.wemon_front_Fu.hidden = NO;
                self.wemon_front_Shengzhi.hidden = NO;
                
                self.wemon_back_jizhu.hidden = YES;
                self.wemon_back_yao.hidden = YES;
                self.wemon_back_penqiang.hidden = YES;
                self.wemon_back_tun.hidden = YES;
                
                
                self.wemon_gebo_left.hidden = YES;
                self.wemon_gebo_right.hidden = YES;
                
                self.manFrontGeboLeft.hidden = NO;
                self.manFrontGebo.hidden = NO;
                self.manBackJing.hidden = NO;
                self.manBackJizhu.hidden = NO;
                self.manBackYao.hidden = NO;
                self.manBackPengqiang.hidden = NO;
                self.manBackTun.hidden = NO;
                
                self.manFrontTou.hidden = NO;
                self.manFrontXiong.hidden = NO;
                self.manFrontFu.hidden = NO;
                self.manFrontShengzhi.hidden = NO;
                self.manFrontXiazhi.hidden =NO;
            }
        }else{
            if (switch2.on) {
                MyNSLog("333");
                
                
                
                self.manImageView.image = [UIImage imageNamed:@"女正"];
                self.wemon_front_tou.hidden = NO;
                self.wemon_front_Jing.hidden = NO;
                self.wemon_front_Xiong.hidden = NO;
                self.wemon_front_Fu.hidden = NO;
                self.wemon_front_Shengzhi.hidden = NO;
                self.wemon_front_Tui.hidden = NO;
                
                self.wemon_back_jizhu.hidden = YES;
                self.wemon_back_yao.hidden = YES;
                self.wemon_back_penqiang.hidden = YES;
                self.wemon_back_tun.hidden = YES;
                
                self.wemon_gebo_left.hidden = NO;
                self.wemon_gebo_right.hidden = NO;
                
                self.manFrontGeboLeft.hidden = YES;
                self.manFrontGebo.hidden = YES;
                self.manBackJing.hidden = YES;
                self.manBackJizhu.hidden = YES;
                self.manBackYao.hidden = YES;
                self.manBackPengqiang.hidden = YES;
                self.manBackTun.hidden = YES;
                
                self.manFrontTou.hidden = YES;
                self.manFrontXiong.hidden = YES;
                self.manFrontFu.hidden = YES;
                self.manFrontShengzhi.hidden = YES;
                self.manFrontXiazhi.hidden =YES;
            }else{
                MyNSLog("444");
                self.manImageView.image = [UIImage imageNamed:@"男正面"];
                self.manBackJing.hidden = NO;
                self.manBackJizhu.hidden = YES;
                self.manBackYao.hidden = YES;
                self.manBackPengqiang.hidden = YES;
                self.manBackTun.hidden = YES;
                
                self.manFrontTou.hidden = NO;
                self.manFrontXiong.hidden = NO;
                self.manFrontFu.hidden = NO;
                self.manFrontShengzhi.hidden = NO;
                self.manFrontXiazhi.hidden =NO;
                
                self.wemon_gebo_left.hidden = YES;
                self.wemon_gebo_right.hidden = YES;
                
                self.manFrontGeboLeft.hidden = NO;
                self.manFrontGebo.hidden = NO;
                
                self.wemon_front_tou.hidden = YES;
                self.wemon_front_Jing.hidden = YES;
                self.wemon_front_Tui.hidden = YES;
                self.wemon_front_Xiong.hidden = YES;
                self.wemon_front_Fu.hidden = YES;
                self.wemon_front_Shengzhi.hidden = YES;
                
                self.wemon_back_jizhu.hidden = YES;
                self.wemon_back_yao.hidden = YES;
                self.wemon_back_penqiang.hidden = YES;
                self.wemon_back_tun.hidden = YES;
                
            }
        }
        
    }else{
        if (switch2.on) {
            if (switch1.on) {
                
                MyNSLog("555");
                self.manImageView.image = [UIImage imageNamed:@"女反"];
                self.wemon_front_tou.hidden = NO;
                self.wemon_front_Jing.hidden = NO;
                self.wemon_front_Tui.hidden = NO;
                
                self.wemon_front_Xiong.hidden = YES;
                self.wemon_front_Fu.hidden = YES;
                self.wemon_front_Shengzhi.hidden = YES;
                
                self.wemon_back_jizhu.hidden = NO;
                self.wemon_back_yao.hidden = NO;
                self.wemon_back_penqiang.hidden = NO;
                self.wemon_back_tun.hidden = NO;
                
                
                self.wemon_gebo_left.hidden = NO;
                self.wemon_gebo_right.hidden = NO;
                
                self.manFrontGeboLeft.hidden = YES;
                self.manFrontGebo.hidden = YES;
                self.manBackJing.hidden = YES;
                self.manBackJizhu.hidden = YES;
                self.manBackYao.hidden = YES;
                self.manBackPengqiang.hidden = YES;
                self.manBackTun.hidden = YES;
                
                self.manFrontTou.hidden = YES;
                self.manFrontXiong.hidden = YES;
                self.manFrontFu.hidden = YES;
                self.manFrontShengzhi.hidden = YES;
                self.manFrontXiazhi.hidden =YES;
                
                
            }else{
                MyNSLog("666");
                self.manImageView.image = [UIImage imageNamed:@"女正"];
                
                self.wemon_front_tou.hidden = NO;
                self.wemon_front_Jing.hidden = NO;
                self.wemon_front_Xiong.hidden = NO;
                self.wemon_front_Fu.hidden = NO;
                self.wemon_front_Shengzhi.hidden = NO;
                self.wemon_front_Tui.hidden = NO;
                
                self.wemon_back_jizhu.hidden = YES;
                self.wemon_back_yao.hidden = YES;
                self.wemon_back_penqiang.hidden = YES;
                self.wemon_back_tun.hidden = YES;
                
                self.wemon_gebo_left.hidden = NO;
                self.wemon_gebo_right.hidden = NO;
                
                self.manFrontGeboLeft.hidden = YES;
                self.manFrontGebo.hidden = YES;
                self.manBackJing.hidden = YES;
                self.manBackJizhu.hidden = YES;
                self.manBackYao.hidden = YES;
                self.manBackPengqiang.hidden = YES;
                self.manBackTun.hidden = YES;
                
                self.manFrontTou.hidden = YES;
                self.manFrontXiong.hidden = YES;
                self.manFrontFu.hidden = YES;
                self.manFrontShengzhi.hidden = YES;
                self.manFrontXiazhi.hidden =YES;
                
            }
        }else{
            if (switch1.on) {
                
                MyNSLog("777");
                self.manImageView.image = [UIImage imageNamed:@"男反面"];
                self.wemon_front_tou.hidden = YES;
                self.wemon_front_Jing.hidden = YES;
                self.wemon_front_Tui.hidden = YES;
                
                self.wemon_front_Xiong.hidden = NO;
                self.wemon_front_Fu.hidden = NO;
                self.wemon_front_Shengzhi.hidden = NO;
                
                self.wemon_back_jizhu.hidden = YES;
                self.wemon_back_yao.hidden = YES;
                self.wemon_back_penqiang.hidden = YES;
                self.wemon_back_tun.hidden = YES;
                
                
                self.wemon_gebo_left.hidden = YES;
                self.wemon_gebo_right.hidden = YES;
                
                self.manFrontGeboLeft.hidden = NO;
                self.manFrontGebo.hidden = NO;
                self.manBackJing.hidden = NO;
                self.manBackJizhu.hidden = NO;
                self.manBackYao.hidden = NO;
                self.manBackPengqiang.hidden = NO;
                self.manBackTun.hidden = NO;
                
                self.manFrontTou.hidden = NO;
                self.manFrontXiong.hidden = NO;
                self.manFrontFu.hidden = NO;
                self.manFrontShengzhi.hidden = NO;
                self.manFrontXiazhi.hidden =NO;
            }else{
                MyNSLog("888");
                self.manImageView.image = [UIImage imageNamed:@"男正面"];
                
                self.manBackJing.hidden = NO;
                self.manBackJizhu.hidden = YES;
                self.manBackYao.hidden = YES;
                self.manBackPengqiang.hidden = YES;
                self.manBackTun.hidden = YES;
                
                self.manFrontTou.hidden = NO;
                self.manFrontXiong.hidden = NO;
                self.manFrontFu.hidden = NO;
                self.manFrontShengzhi.hidden = NO;
                self.manFrontXiazhi.hidden =NO;
                
                self.wemon_gebo_left.hidden = YES;
                self.wemon_gebo_right.hidden = YES;
                
                self.manFrontGeboLeft.hidden = NO;
                self.manFrontGebo.hidden = NO;
                
                self.wemon_front_tou.hidden = YES;
                self.wemon_front_Jing.hidden = YES;
                self.wemon_front_Tui.hidden = YES;
                self.wemon_front_Xiong.hidden = YES;
                self.wemon_front_Fu.hidden = YES;
                self.wemon_front_Shengzhi.hidden = YES;
                
                self.wemon_back_jizhu.hidden = YES;
                self.wemon_back_yao.hidden = YES;
                self.wemon_back_penqiang.hidden = YES;
                self.wemon_back_tun.hidden = YES;
                
            }
            
        }
    }
}


@end
